package com.study.lihan.threalLocal;

import java.lang.ref.SoftReference;

/**
 * @Author: lihan
 * @Date : 2022/1/2- 01
 * @DESCRIPTION: com.study.lihan.threalLocal
 * @version: 1.0
 */
public class TestSoftReference {
    public static void main(String[] args) {
        SoftReference<byte[]> softReference = new SoftReference<>(new byte[1024*1024*10]);
//        softReference = null;
        System.out.println(softReference.get());
        System.gc();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(softReference.get());
//在分配一个数组，heap将装不下，这时候系统会垃圾回收，先回收一次，如果不够会把软引用回收
        byte[] b = new byte[1024*1024*15];
        System.out.println(softReference.get());
    }
}
